 
 domains
   disease , symptom = symbol
   query = string
   reply = char
   
 database
   xpositive (symptom)
   xnegative (symptom)
   
 predicates
   hypothesis (disease)
   symptom (symptom)
   response (reply)
   go
   positive (query,symptom)
   clear_facts
   remember (symptom,reply)
   ask (query,symptom,reply)
   
 clauses

   go :-
     clearwindow,
     hypothesis (Disease),
     !,
     write ("The patient probably has ",Disease),
     nl,
     save ("DYNAMIC.DBF"),
     clear_facts.
     
   go :-
     write ("Sorry, I don't seem to be able to "),
     write ("diagnose the disease."),
     nl,
     clear_facts.
     
   positive (_,Symptom) :-
     xpositive (Symptom),
     !.
     
   positive (Query,Symptom) :-
     not (xnegative(Symptom)),
     ask (Query,Symptom,Reply),
     Reply = 'y'.
     
   ask (Query,Symptom,Reply) :-
     write (Query),
     readchar (Reply),
     write (Reply),
     nl,
     remember (Symptom,Reply).
     
   remember (Symptom,'y') :-
     asserta (xpositive(Symptom)).
     
   remember (Symptom,'n') :-
     asserta (xnegative(Symptom)).
     
   clear_facts :-
     retract (xpositive(_)),
     fail.
     
   clear_facts :-
     retract (xnegative(_)),
     fail.
     
   clear_facts.
     
   symptom (fever) :-
     positive ("Does the patient have a fever (y/n) ? ",fever).
   
   symptom (rash) :-
     positive ("Does the patient have a rash (y/n) ? ",rash).
   
   symptom (headache) :-
     positive ("Does the patient have a headache (y/n) ? ",headache).
   
   symptom (runny_nose) :-
     positive ("Does the patient have a runny nose (y/n) ? ",runny_nose).
     
   symptom (conjuntivitis) :-
     positive ("Does the patient have a conjuntivitis (y/n) ? ",conjuntivitis).
   
   symptom (cough) :-
     positive ("Does the patient have a cough (y/n) ? ",cough).
   
   symptom (body_ache) :-
     positive ("Does the patient have a body ache (y/n) ? ",body_ache).
   
   symptom (chills) :-
     positive ("Does the patient have chills (y/n) ? ",chills).
     
   symptom (sore_throat) :-
     positive ("Does the patient have a sore throat (y/n) ? ",sore_throat).
   
   symptom (sneezing) :-
     positive ("Is the patient sneezing (y/n) ? ",sneezing).
   
   symptom (swollen_glands) :-
     positive ("Does the patient have swollen glands (y/n) ? ",swollen_glands).
   
   hypothesis (measles) :-
     symptom (fever),
     symptom (cough),
     symptom (conjunctivitis),
     symptom (runny_nose),
     symptom (rash).
     
   hypothesis (german_measles) :-
     symptom (fever),
     symptom (headache),
     symptom (runny_nose),
     symptom (rash).  
     
   hypothesis (flu) :-
     symptom (fever),
     symptom (headache),
     symptom (body_ache),
     symptom (conjuctivitis),
     symptom (chills),
     symptom (sore_throat),
     symptom (runny_nose),
     symptom (cough).
     
   hypothesis (common_cold) :-
     symptom (headache),
     symptom (sneezing),
     symptom (sore_throat),
     symptom (chills),
     symptom (runny_nose).
     
   hypothesis (mumps) :-
     symptom (fever),
     symptom (swollen_glands).
     
   hypothesis (chicken_pox) :-
     symptom (fever),
     symptom (rash),
     symptom (body_ache),
     symptom (chills).
     
   hypothesis (whooping_cough) :-
     symptom (cough),
     symptom (sneezing),
     symptom (runny_nose).
     
   response (Reply) :-
     readchar (Reply),
     write (Reply),
     nl.
     